<?php

namespace App\Models\Member;

use Illuminate\Database\Eloquent\Model;


class User extends Model
{
    protected $table = 'jxt_member_user';

    public $timestamps = false;

    public static function boot()
    {
        parent::boot();
        static::saving(function ($model) {

            if ($model->getOriginal('vip_id') != $model->vip_id) {
                $vip_price = Price::where('id', $model->vip_id)->select(['id', 'term'])->first();
                if ($vip_price) {
                    $model->create_at = time();
                    $model->start_time = time();
                    $model->expiry_time = strtotime('+' . $vip_price->term . ' month', time());
                }
            }

        });
    }


    public function price()
    {
        return $this->belongsTo(Price::class,'vip_id');
    }

    public function user()
    {
        return $this->belongsTo(App\Models\User\User::class,'user_id' , 'vip_id');
    }





}
